/**
 * Created by HUARO on 2016/3/21 0021.
 */
//志愿者注册
function findVolName(){
	var uname=$("#vuname").val();
	$.post("/happinesshome/find/vfind",{name:uname},function(data){
		if(data.success){
			alert("没有注册成功，此用户名已经存在或直接登录！");
		}else{
			v_register();
		}
	},"json");
	return false;
}
function findEldName(){
	var uname=$("#euname").val();
	$.post("/happinesshome/find/efind",{name:uname},function(data){
		if(data.success){
			alert("没有注册成功，此用户名已经存在或直接登录！");
		}else{
			e_register();
		}
	},"json");
	return false;
}
function v_register(){
	var uname=$("#vuname").val();
	var upwd1=$("#vpassword").val();
	var upwd2=$("#vpassword2").val();
	var usex=$("#vsex").val();
	var uaddress=$("#vaddress").val();
	var utype=$("#vtype").val();
	if(upwd1!=upwd2){
		alert("两次密码不相同，请重新输入");
	}else{
		$.post("/happinesshome/user/vregister",{vuname:uname,vpwd:upwd1,vsex:usex,vaddress:uaddress,vtype:utype},function(data){
			if(data.success){
				location.href="login.jsp";
			}else{
				alert("没有注册成功，此用户名已经存在或直接登录！");
			}
		},"json");
	}
	return false;
}
function e_register(){
	var uname=$("#euname").val();
	var upwd1=$("#epassword").val();
	var upwd2=$("#epassword2").val();
	var usex=$("#esex").val();
	var uaddress=$("#eaddress").val();
	var uaddress3=$("#eaddress3").val();
	if(upwd1!=upwd2){
		alert("两次密码不相同，请重新输入");
	}else{
		$.post("/happinesshome/user/eregister",{vuname:uname,vpwd:upwd1,vsex:usex,vaddress:uaddress,vaddress3:uaddress3},function(data){
			if(data.success){
				location.href="login.jsp";
			}else{
				alert("没有注册成功，请重试！");
			}
		},"json");
	}
	return false;
}
function user_login(){
	var uname=$("#uname").val();
	var upwd=$("#upwd").val();
	
	$.post("/happinesshome/user/login",{name:uname,pwd:upwd},function(data){
		if(data.success=="volunteer"){
			location.href="my.jsp";
		}else if(data.success=="elder"){
			location.href="index.jsp";
		}else if(data.success=="admin"){
			location.href="/back/backHome.jsp";
		}else if(data.success=="error"){
			alert("登录失败，登录名或密码错误！");
		}
	},"json");
	return false;
}